var express = require('express');
var config = require('./config/index');

var port = process.env.PORT || config.build.port;

var app = express();

var router = express.Router();

router.get('/', function (req, res, next) {
  req.url = '/index.html';
  next();
});

var appData = require('./index.json')
var cityData = require('./city.json')
var detailData = require('./detail.json')

router.get('/index', function (req, res) {
  console.log(req.query)
  res.json({
    errno: 0,
    data: appData
  })
})

router.get('/city', function (req, res) {
  res.json({
    errno: 0,
    data: cityData
  })
});
router.get('/detail', function (req, res) {
  res.json({
    errno: 0,
    data: detailData
  })
})

app.use('/api', router);
app.use(express.static('./dist'));

module.exports = app.listen(port, function (err) {
  if (err) {
    console.log(err);
    return
  }
  console.log('Listening at http://localhost:' + port + '\n')
});